package com.example.win.android_banduyujia.peopleactivity.activity.activity;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.widget.RadioGroup;

import com.example.win.android_banduyujia.R;
import com.example.win.android_banduyujia.peopleactivity.adapter.ViewPageAdapter;
import com.example.win.android_banduyujia.peopleactivity.fragment.doorfragment.DoorFragment;
import com.example.win.android_banduyujia.peopleactivity.fragment.doorfragment.NodoorFragment;
import com.example.win.android_banduyujia.peopleactivity.ui.activity.BaseTitleBarActivity;

import java.util.ArrayList;

/**
 * Created by huchun on 2015/8/17.
 */
public class TarActivity extends BaseTitleBarActivity {
    private static final  String  TAG = TarActivity.class.getSimpleName();

    private RadioGroup  mTarRG;
    private ViewPager   mViewPager;

    private ArrayList<Fragment>  mFragmentList=new ArrayList<Fragment>();
    private ViewPageAdapter      mAdapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.layout_page_release_private_teaching);

        InitTitles();
        InitFragment();
        InitViews();
    }

    private void InitTitles() {
        showLeftBackButton();
        setTitle(R.string.fragment_my_release);
        setRightTextViewListener(R.string.title_text_view_que_project, onRightListener);
    }

    private void InitFragment() {
        DoorFragment doorFragemnt = new  DoorFragment();
        NodoorFragment nodoorFragment = new NodoorFragment();
        mFragmentList.add(doorFragemnt);
        mFragmentList.add(nodoorFragment);
    }

    @Override
    protected void onResume() {
        super.onResume();

        mAdapter = new ViewPageAdapter(getSupportFragmentManager(), mFragmentList);
        mViewPager.setAdapter(mAdapter);
    }

    private View.OnClickListener onLeftListener = new View.OnClickListener(){

        @Override
        public void onClick(View v) {
             TarActivity.this.finish();
        }   };

    private View.OnClickListener onRightListener = new View.OnClickListener(){

        @Override
        public void onClick(View v) {
             FastActivity();
        }  };

    private void FastActivity() {

    }

    private void InitViews() {
        mTarRG = (RadioGroup) findViewById(R.id.radio_group_private_teaching);
        mTarRG.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                switch (checkedId){
                    case R.id.radio_edit_visit:
                        mViewPager.setCurrentItem(0);
                        break;
                    case R.id.radio_review_no_visit:
                        mViewPager.setCurrentItem(1);
                        break;
                }
            }
        });

        mViewPager = (ViewPager) findViewById(R.id.private_teaching_viewPager);
        mViewPager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int i, float v, int i2) { }

            @Override
            public void onPageSelected(int i) {
                switch (i){
                    case 0:
                        mTarRG.check(R.id.radio_edit_visit);
                        break;
                    case 1:
                        mTarRG.check(R.id.radio_review_no_visit);
                        break;
                }
            }

            @Override
            public void onPageScrollStateChanged(int i) { }
        });
    }
}
